<?php
namespace app\apps\controller;
use framework\ext\Check;
/* *
 * 应用管理
 * */
class vipController extends \app\base\controller\AdminController{

    //列表
    public function index(){
        $act = $_GET['act'];
        if($act == 'del'){
            $fid = intval($_GET['id']);
            $result =  model('vip')->_delete($fid);
            if($result){
                $this->jsonMsg('删除成功',1);
            }else{
                $this->jsonMsg('删除失败');
            }
        }else{
            $page = form('get.page',0,intval);
            $this->list = model('vip')->pager($page,20)->_select();
            $this->pager = $this->getPage(model('vip')->pager);
            $this->display();
        }
    }
    //编辑
    public function edit(){
        if($this->isPost()){
            $msg = Check::rule(
                    array(check::must($_POST['app']),'APPID必须填写'),
                    array(check::must($_POST['appname']),'应用名称必须填写'),
                    array(check::must($_POST['name']),'网站名称必须填写'),
                    array(check::must($_POST['url']),'授权网址必须填写'),
                    array(check::must($_POST['vipuser']),'授权持有人必须填写'),
                    array(check::must($_POST['viptime']),'授权起始时间必须填写'),
                    array(check::must($_POST['services']),'服务起止日期必须填写')
                    );
            if(true !== $msg){
                $this->jsonMsg($msg);
            }
            $fid = form('post.fid',0,intval);
            $data = form('post',array('fid'));
            if($fid){
                $condition['id'] = $fid;
                $rel = model('vip')->_update($data,$condition);
            }else{
                $rel = model('vip')->_update($data);
            }
            if($rel){
                $this->jsonMsg('增加或编辑成功',1,url('vip/index'));
            }else{
                $this->jsonMsg('增加或编辑失败');
            }
        }else{
            $this->fid = form('get.id',0,intval);
            $this->info = model('vip')->_find(array('id'=>$this->fid));
            $this->display(); 
        }
    }
    //在线更新
    public function updete(){
    	$app = $_GET['app'];
        $condition['app'] = $app;
        $rel = model('version')->find($condition); 
        if($rel){
            $updateurl = 'http://www.easyes.com.cn'.__PUBLICAPP__.'/'.$rel['down'];   //更新地址
            $str = array('info'=>$rel['info'],'var'=>$rel['var'],'url' =>$updateurl);
        }
    	echo json_encode($str);
    }
    //授权验证
    public function vip(){
    	$app = $_GET['app'];
    	$url = $_GET['url'];
        $condition['app'] = $app;
        $condition['url'] = $url;
        $rel = model('vip')->find($condition); 
        $vipurl = 'http://www.easyes.com.cn'.url('appstore/varkeys/certificate',array('app'=>$app,'url'=>$url));
        if($rel){
            $str = array('info'=>'尊敬的VIP用户:'.$rel['vipuser'].'您好,点击确认查看您的认证信息','url' =>$vipurl);
        }else{
            $str = array('info'=>'未查询到您的正版认证信息','url' =>$vipurl );
        }
        echo json_encode($str);
    }
    //授权证书
    public function certificate(){

    }
}